﻿@model KPIS.GERP.Models.ICM.DeliveryNote
@using KPIS.GERP.Models.ICM

@if (ViewContext.RouteData.Values["action"].ToString().ToLower() == "Create")
{ @Html.HiddenFor(model => model.PoId) }
@if (ViewContext.RouteData.Values["action"].ToString().ToLower() == "edit")
{
    @Html.HiddenFor(model => model.DnId)
    @Html.HiddenFor(model => model.PoId)
    @Html.HiddenFor(model=>model.Code)
}

<div class="widget-box span9">
    <div class="widget-header">
        <h4 class="smaller">ข้อมูลหลัก</h4>
    </div>

    <div class="widget-body">
        <div class="widget-main">

            <div class="control-group">
                <div class="control-label">
                    @Html.LabelFor(model => model.DocumentNumber)
                </div>
                <div class="controls"> 
                    <input id="DNCODE_" name="DNCODE_" type="text" class="text-box single-line"
                    value="@Model.PurchaseOrder.Code"
                    readonly>
                </div>
            </div>

            <div class="control-group">
                <div class="control-label">
                    <label for="Name">รหัสอ้างอิง</label>
                </div>
                <div class="controls"> 
                    <input id="DNCODE_" name="DNCODE_" type="text" class="text-box single-line"
                           value="@(Model == null || string.IsNullOrEmpty(Model.Code) ? CodeGenerate.GetNextCode(CodeGenerate.TransectionType.DeliveryNote) : Model.Code)" 
                            readonly>
                </div>
            </div>

            <div class="control-group">
                <div class="control-label">
                    <label for="Name">ชื่อเรื่องรายการตรวจรับ</label>
                </div>
                <div class="controls">
                    @Html.TextBoxFor(model => model.Name, new { style = "width:80%;min-width:206px;" })

                </div>
            </div>
            
            
            <div class="control-group">
                <div class="control-label">
                    @*@Html.LabelFor(model => model.DeliveryDate)*@

                    <label for="DeliveryDate">วันกำหนดส่งมอบ</label>
                </div>
                <div class="controls">

                    <select id="DnDateBy" name="DnDateBy" onchange="onchangedateby()">
                        <option value="12">วันที่ใบแจ้งหนี้</option>
                        <option value="13">วันที่ส่งสินค้า</option>
                        <option value="14">วันที่ส่งมอบงาน</option>
                    </select>
                    @Html.EditorFor(model => model.DeliveryDate)

                    <input type="hidden" id="PoRequireDate"
                           value="@(Model.PurchaseOrder.RequireDate.HasValue ?
                                Model.PurchaseOrder.RequireDate.Value.ToString("d/M/yyyy") : "")" />
                    <input type="hidden" id="MockReceiptDate"
                           value="@((Model.ReceiveDate.HasValue ? Model.ReceiveDate.Value : DateTime.Now).ToString("d/M/yyyy"))" />
                    <span id="lblPoRequireDate" style="color:goldenrod;">
                        <br />
                        @(Model.PurchaseOrder != null && Model.PurchaseOrder.RequireDate.HasValue ?
                            "วันครบกำหนดส่ง " + Model.PurchaseOrder.Code + ": " +
                            Model.PurchaseOrder.RequireDate.Value.ToString("d/M/yyyy")
                            : "")
                    </span>
                </div>
            </div>

            <div class="control-group" >
                <div class="control-label">
                    <label for="ChkTaxInvoice">ประเภทใบกำกับภาษี</label>
                </div>
                <div class="controls"> 
                    <table>
                        <tr>
                            <td>
                                <label>
                                    <input type="radio" name="ChkTaxInvoice" value="false" @(Model != null && Model.ChkTaxInvoice != true ? "checked":"") />
                                    <span class="lbl">ใบส่งของ</span>
                                </label>
                            </td>
                            <td>
                                <label>
                                    <input type="radio" name="ChkTaxInvoice" value="true" @(Model != null && Model.ChkTaxInvoice == true ? "checked":"") />
                                    <span class="lbl">ใบกำกับภาษี</span>
                                </label>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="control-group">
                <div class="control-label">
                    @Html.LabelFor(model => model.InvoiceNumber)
                </div>
                <div class="controls">
                    @Html.EditorFor(model => model.InvoiceNumber)
                </div>
            </div>

            <div class="control-group">
                <div class="control-label">
                    <label for="InvoiceDate">วันที่ใบแจ้งหนี้</label>
                </div>
                <div class="controls">
                    @Html.EditorFor(model => model.InvoiceDate)
                </div>
            </div>


            <div class="control-group">
                <div class="control-label">
                    <label for="InvoiceDate">วันที่ตรวจรับ</label>
                </div>
                <div class="controls">
                    @Html.EditorFor(model => model.ReceiveDate)
                </div>
            </div>

            <div class="control-group">
                <div class="control-label">
                    @Html.LabelFor(model => model.DeliveryPlace)
                </div>
                <div class="controls">
                    @Html.TextBoxFor(model => model.DeliveryPlace, new { style = "width:80%;min-width:206px;" })

                </div>
            </div>

            <div class="control-group">
                <div class="control-label">
                    <label for="WhId">คลังพัสดุที่จะรับเข้าคลัง</label>
                </div>
                <div class="controls">
                    @Html.DropDownListFor(model => model.WhId, new KPIS.GERP.WEB.GIMS.WarehouseService.WarehouseServiceClient().SelectListWarehouse(null))
                </div>
            </div>

            <div class="control-group">
                <div class="control-label">
                    <label for="Descr">รายละเอียด</label>
                </div>
                <div class="controls">
                    @Html.TextAreaFor(model => model.Descr, 5, 300, new { style = "width:80%;min-width:206px;" })
                </div>
            </div>


            <div class="control-group">
                <div class="controls" hidden="hidden">
                    @Html.EditorFor(model => model.PoId)
                </div>
                <div class="controls" hidden="hidden">
                    @Html.EditorFor(model => model.PoInstallId)
                </div>
            </div>

            <div class="control-group" style="visibility: collapse;">
                <div class="control-label">
                    @*@Html.LabelFor(model => model.ReceiveDate)*@
                    <label for="ReceiveDate">วันที่ตรวจรับ</label>
                </div>
                <div class="controls">
                    @Html.EditorFor(model => model.ReceiveDate)
                </div>
            </div>



        </div>
    </div>
</div>



<script>
    function onchangedateby() {
        var by = $("#DnDateBy").val();
        switch (by) {
            case "12":
                $("#DeliveryDate").val($("#InvoiceDate").val());
                $("#lblPoRequireDate").hide();
                break;
            case "13":
                $("#DeliveryDate").val($("#MockReceiptDate").val());
                $("#lblPoRequireDate").hide();
                break;
            case "14":
                $("#DeliveryDate").val($("#PoRequireDate").val());
                $("#lblPoRequireDate").show();
                break;
        }
    }

</script>